{include file="public/nheader"}
<style type="text/css">
    #lay-tableList {
        height: auto;
    }
</style>
<style type="text/css">
    .layui-table-view .layui-table[lay-size=lg] .layui-table-cell {
        height: auto;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input type="text" name="created[startime]" autocomplete="off" lay-datetime=""
                                class="layui-input" placeholder="下单时间开始">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline ">
                            <input type="text" name="created[endtime]" autocomplete="off" lay-datetime=""
                                class="layui-input" placeholder="下单时间结束">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="status" lay-verify="">
                                <option value="">状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>待付款</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>待接单</option>
                                <option value="3" {if !empty(input('get.status')) &&
                                    input('get.status')==3}selected{/if}>服务中</option>
                                <option value="4" {if !empty(input('get.status')) &&
                                    input('get.status')==4}selected{/if}>已服务</option>
                                <option value="5" {if !empty(input('get.status')) &&
                                    input('get.status')==5}selected{/if}>已取消</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="payment" lay-verify="">
                                <option value="">支付方式</option>
                                <option value="1" {if !empty(input('get.payment')) &&
                                    input('get.payment')==1}selected{/if}>线下支付</option>
                                <option value="2" {if !empty(input('get.payment')) &&
                                    input('get.payment')==2}selected{/if}>微信支付</option>
                                <option value="3" {if !empty(input('get.payment')) &&
                                    input('get.payment')==3}selected{/if}>抖音支付</option>
                                <option value="4" {if !empty(input('get.payment')) &&
                                    input('get.payment')==4}selected{/if}>余额支付</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="agentid" lay-search>
                                <option value="">请选择代理</option>
                                {foreach $agent as $v}
                                <option value="{$v.id}" {if !empty(input('get.agentid')) &&
                                    input('get.agentid')==$v.id}selected{/if}>{$v.nickname}({$v.accounts})</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="riderid" lay-search>
                                <option value="">请选择师傅</option>
                                {foreach $rider as $v}
                                <option value="{$v.id}" {if !empty(input('get.riderid')) &&
                                    input('get.riderid')==$v.id}selected{/if}>{$v.name}({$v.mobile})</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="province" lay-filter="province">
                                <option value="">请选择搜索省份</option>
                                {foreach $province as $v}
                                <option value="{$v.area_code}" {if !empty(input('get.province')) &&
                                    input('get.province')==$v.area_code}selected{/if}>{$v.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="city" lay-filter="city">
                                <option value="">请选择搜索城市</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="area" lay-filter="area">
                                <option value="">请选择搜索区域</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="street" lay-filter="street">
                                <option value="">请选择搜索街道</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="issystem" lay-verify="">
                                <option value="">订单类型</option>
                                <option value="1" {if empty(input('get.issystem')) ||
                                    input('get.issystem')==1}selected{/if}>自然单</option>
                                <option value="2" {if !empty(input('get.issystem')) &&
                                    input('get.issystem')==2}selected{/if}>系统单</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="ID|订单号|用户名|手机号" />
                        </div>
                    </div>

                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- <script type="text/html" id="tableBar1">
</script> -->
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" lay-open data-title="查看订单" data-area="50%,70%" data-url="/orders/order_edit?id={{d.id}}" >查看订单</a>
    {{#  if(d.status ==1){ }}
    <div class="layui-divider layui-divider-vertical"></div>
        <a class="layui-table-text" style="color:#FF5722" data-url="/orders/order_status?id={{d.id}}&status=5" data-reload="self" data-confirm="" lay-ajax="">取消</a>
    {{# }if(d.status ==2) { }}
    <div class="layui-divider layui-divider-vertical"></div>
        <a class="layui-table-text" data-title="指派师傅" data-area="30%,40%" callback="edits" data-url="#adminforms"  lay-event="edit">指派师傅</a>
        <br/>
        <a class="layui-table-text" style="color:#FF5722" data-url="/orders/order_status?id={{d.id}}&status=5" data-reload="self" data-confirm="" lay-ajax="">取消</a>
        <div class="layui-divider layui-divider-vertical"></div>
        <a class="layui-table-text" data-url="/orders/order_status?id={{d.id}}&status=4" data-confirm="" lay-ajax="" data-reload="self">完结</a>
    {{# }if(d.status ==3) { }}
        <div class="layui-divider layui-divider-vertical"></div>
        <a class="layui-table-text" data-title="更换师傅" data-area="30%,40%" callback="edits" data-url="#adminforms"  lay-event="edit">更换师傅</a>
        <br/>
        <a class="layui-table-text" data-url="/orders/order_status?id={{d.id}}&status=4" data-confirm="" lay-ajax="" data-reload="self">完结</a>
        <div class="layui-divider layui-divider-vertical"></div>
        <a class="layui-table-text" style="color:#FF5722" data-url="/orders/order_status?id={{d.id}}&status=5" data-reload="self" data-confirm="" lay-ajax="">取消</a>
    {{#  } }}
</script>

<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>师傅账号</label>
            <div class="layui-input-block">
                <input name="ridermobile"  placeholder="请填写师傅账号" type="number" class="layui-input" lay-verify="required" />
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {
        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {

                // 获取用户id
                var pageThat = layui.$(this);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                post.field.status = 3;
                layui.$.post("{:url('orders/order_status')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                    }
                    else {
                        layer.error(res.msg);
                    }
                }, 'json');
                return false;
            })
        }
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , where: {
                riderid: "{:input('riderid/d',0)}", agentid: "{:input('agentid/d',0)}", status: "{:input('status/d',0)}", issystem: "{:input('issystem/d',1)}"
            }
            , toolbar: 'true'
            // , defaultToolbar: ["filter","exports","print"]
            , defaultToolbar: [{
                title: '导出excel' //标题
                , layEvent: 'LAYTABLE_EXPORT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-export' //图标类名
            }, {
                title: '打印页面' //标题
                , layEvent: 'LAYTABLE_PRINT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-print' //图标类名
            }, {
                title: '筛选数据' //标题
                , layEvent: 'LAYTABLE_COLS' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-cols' //图标类名
            }]
            , even: true
            , loading: true
            , limits: [10, 20, 40, 60, 80, 100, 150, 200, 300]
            , limit: 10
            , cols: [[
                // { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { align: 'center', width: 200, toolbar: '#tableBar', title: '操作' },
                { field: 'ordersn', width: 160, align: 'center', title: '订单号' },
                // {
                //     field: 'name', align: 'center', width: 250, templet: function (d) {
                //         return d.posaddress + '&nbsp;' + d.address;
                //     }, title: '详细地址'
                // },
                {
                    field: 'name', align: 'center', width: 200, templet: function (d) {
                        return d.name + '<a class="layui-table-text" style="color:red" lay-open data-title="账号" data-area="50%,70%" data-url="/user/index?id=' + d.user_id + '" >(查看下单账号)</a>' + '&nbsp;<br/>' + d.mobile;
                    }, title: '用户联系方式'
                },
                {
                    field: 'name', align: 'center', width: 200, templet: function (d) {
                        return d.ridername + '&nbsp;<br/>' + d.ridermobile;
                    }, title: '师傅联系方式'
                },
                {
                    field: 'status_text', width: 220, align: 'center', title: '订单及支付方式', templet: function (d) {
                        return d.status_text + '(' + d.payment_text + ')';
                    }
                },
                {
                    field: 'ptotal', width: 200, align: 'center', title: '原价/支付价', templet: function (d) {
                        return d.ptotal + '元/' + d.total + '元';
                    }
                },
                {
                    field: 'created', width: 200, align: 'center', title: '创建时间'
                },
                {
                    field: 'province_text', align: 'center', width: 350, templet: function (d) {
                        return d.city_text + d.area_text + d.street_text + '<br/>（' + d.posaddress + '&nbsp;' + d.address + ')';
                    }, title: '地址信息'
                },
            ]]
        })
    })
</script>